﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using fanfu.Model;
using fanfu.Common;
using System.Data.SqlClient;

namespace fanfu.Business
{
    public class LeavewordRule
    {
        #region 获取所有留言信息
        /// <summary>
        /// 获取所有留言信息
        /// </summary>
        public DataTable GetAllLeavewordInfo()
        {
            string sqlString = "SELECT * FROM Leaveword ORDER BY LeaveTime ASC";
            DataTable dt = SqlHelper.GetDataTable(sqlString);
            return dt;
        }
        #endregion

        #region 获取指定ID的留言信息
        /// <summary>
        /// 获取指定ID的留言信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public LeavewordModel GetLeavewordByID(string ID)
        {
            string sqlString = "SELECT TOP 1 * FROM Leaveword WHERE ID=@ID";
            SqlParameter para = new SqlParameter("@ID", ID);
            DataTable dt = SqlHelper.GetDataTable(sqlString, para);
            if (dt.Rows.Count == 1)
                return new LeavewordModel(dt.Rows[0]);
            else
                return null;
        }
        #endregion

        #region 删除指定ID的留言信息
        /// <summary>
        /// 删除指定ID的留言信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int DeleteLeaveword(string ID)
        {
            string sqlString = string.Format("UPDATE Leaveword SET Flag={0} WHERE ID={1}", (int)LeavewordFlag.noPass, ID);
            return SqlHelper.ExecuteCommand(sqlString);
        }
        #endregion

        #region 留言状态枚举值转换
        /// <summary>
        /// 留言状态枚举值转换
        /// </summary>
        public string GetFlagDes(object objFlag)
        {
            string strResult = string.Empty;
            int flag = Convert.ToInt32(objFlag);
            switch (flag)
            {
                case (int)LeavewordFlag.noVerify: strResult = "未审核"; break;
                case (int)LeavewordFlag.passVerify: strResult = "已审核"; break;
                case (int)LeavewordFlag.noPass: strResult = "未通过"; break;
            }
            return strResult;
        }
        #endregion

        #region 获取所有已经审核通过的留言信息
        /// <summary>
        /// 获取所有已经审核通过的留言信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllLeavewordInfoByPassVerify()
        {
            string sqlString = "SELECT * FROM Leaveword WHERE Flag=" + (int)LeavewordFlag.passVerify;
            DataTable dt = SqlHelper.GetDataTable(sqlString);
            return dt;
        }
        #endregion
    }
}
